<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>对象拷贝</title>
  <script type="text/javascript">
    // 浅拷贝,类似java对象的引用
    let person = {
      name: "tom",
      age: 18
    }
    let p1 = person;
    p1.age = 20;
    console.log("person:", person);
    console.log("p1:", p1);
    // 深拷贝
    let p2 = {...person};
    p2.name = "jack";
    console.log("person:", person);
    console.log("p1:", p1);
    console.log("p2:", p2);
    // 合并拷贝
    let cat = {name: "bob", age: 2}
    let position = {x: 10, y: 20};
    let Cat = {...cat, ...position};
    console.log("Cat:", Cat);
  </script>
</head>
<body>

</body>
</html>
